# CloudResearch 1 - Political Knowledge ----------------------------------------
A <- designMatrices(resp=cr1_political_knowledge)$A
A1 <- A
dimnames(A1)[[1]] <- colnames(cr1_political_knowledge)
A1[1,,] = A1[15,,]
A1[2,,] = A1[16,,]
A1[3,,] = A1[17,,]
A1[4,,] = A1[18,,]
A1[5,,] = A1[19,,]
A1[6,,] = A1[20,,]
A1[7,,] = A1[21,,]
A1[8,,] = A1[22,,]
A1[9,,] = A1[23,,]
A1[10,,] = A1[24,,]
A1[11,,] = A1[25,,]
A1[12,,] = A1[26,,]
A1[13,,] = A1[27,,]
A1[14,,] = A1[28,,]

cr1_pkscale_m <- tam.mml.2pl(cr1_political_knowledge,
                             group = cr1_language_group,
                             irtmodel = "GPCM",
                             beta.fixed = cbind(c(1:3), 
                                                1, c(0, 0, 0)),
                             A = A1)

cr1_pkscale_m <- tam.mml.2pl(cr1_political_knowledge,
                             group = cr1_language_group,
                             irtmodel = "GPCM",
                             beta.fixed = cbind(c(1:3), 
                                                1, c(0, 0, 0)),
                             A = A1,
                             xsi.fixed = cbind(which(cr1_pkscale_m$xsi.fixed.estimated[,2] == 0), 
                                               which(cr1_pkscale_m$xsi.fixed.estimated[,2] != 0)))

cr1_pkscale_m2 <- tam.mml.2pl(cr1_political_knowledge,
                              group = cr1_language_group,
                              irtmodel = "GPCM",
                              beta.fixed = cbind( c(1:3), 
                                                  1, c(0, 0, 0)))

row.names(cr1_pkscale_m2$xsi) <- c(paste("polknow", "_e_", 1:14, sep = ""), 
                                   paste("polknow", "_s_", 1:14, sep = ""))

cr1_pkscale_lr_ef <- IRT.compareModels(cr1_pkscale_m,
                                    cr1_pkscale_m2)

# CloudResearch 1 - Panethnic Identity -----------------------------------------
A <- designMatrices(resp=cr1_panethnic)$A
A1 <- A
dimnames(A1)[[1]] <- colnames(cr1_panethnic)
A1[1,,] = A1[6,,]
A1[2,,] = A1[7,,]
A1[3,,] = A1[8,,]
A1[4,,] = A1[9,,]
A1[5,,] = A1[10,,]

cr1_panethnic_m <- tam.mml.2pl(cr1_panethnic,
                               group = cr1_language_group,
                               irtmodel = "GPCM",
                               beta.fixed = cbind(c(1:3), 
                                                  1, c(0, 0, 0)),
                               A = A1)

cr1_panethnic_m <- tam.mml.2pl(cr1_panethnic,
                               group = cr1_language_group,
                               irtmodel = "GPCM",
                               beta.fixed = cbind(c(1:3), 
                                                  1, c(0, 0, 0)),
                               A = A1,
                               xsi.fixed = cbind(which(cr1_panethnic_m$xsi.fixed.estimated[,2] == 0), 
                                                 which(cr1_panethnic_m$xsi.fixed.estimated[,2] != 0)))

cr1_panethnic_m2 <- tam.mml.2pl(cr1_panethnic,
                                group = cr1_language_group,
                                irtmodel = "GPCM",
                                beta.fixed = cbind( c(1:3), 
                                                    1, c(0, 0, 0)))

cr1_panethnic_lr_ef <- IRT.compareModels(cr1_panethnic_m,
                                      cr1_panethnic_m2)

# CloudResearch 1 - Efficacy Beliefs -----------------------------------------------
A <- designMatrices(resp=cr1_efficacy)$A
A1 <- A
dimnames(A1)[[1]] <- colnames(cr1_efficacy)
A1[1,,] = A1[7,,]
A1[2,,] = A1[8,,]
A1[3,,] = A1[9,,]
A1[4,,] = A1[10,,]
A1[5,,] = A1[11,,]
A1[6,,] = A1[12,,]

cr1_efficacy_m <- tam.mml.2pl(cr1_efficacy,
                              group = cr1_language_group,
                              irtmodel = "GPCM",
                              beta.fixed = cbind(c(1:3), 
                                                 1, c(0, 0, 0)),
                              A = A1)

cr1_efficacy_m <- tam.mml.2pl(cr1_efficacy,
                              group = cr1_language_group,
                              irtmodel = "GPCM",
                              beta.fixed = cbind(c(1:3), 
                                                 1, c(0, 0, 0)),
                              A = A1,
                              xsi.fixed = cbind(which(cr1_efficacy_m$xsi.fixed.estimated[,2] == 0), 
                                                which(cr1_efficacy_m$xsi.fixed.estimated[,2] != 0)))

cr1_efficacy_m2 <- tam.mml.2pl(cr1_efficacy,
                               group = cr1_language_group,
                               irtmodel = "GPCM",
                               beta.fixed = cbind( c(1:3), 
                                                   1, c(0, 0, 0)))

cr1_efficacy_lr_ef <- IRT.compareModels(cr1_efficacy_m,
                                     cr1_efficacy_m2)


# CloudResearch 1 - Minority Representation -----------------------------------------------
A <- designMatrices(resp=cr1_minrep)$A
A1 <- A
dimnames(A1)[[1]] <- colnames(cr1_minrep)
A1[1,,] = A1[4,,]
A1[2,,] = A1[5,,]
A1[3,,] = A1[6,,]

cr1_minrep_m <- tam.mml.2pl(cr1_minrep,
                            group = cr1_language_group,
                            irtmodel = "GPCM",
                            beta.fixed = cbind(c(1:3), 
                                               1, c(0, 0, 0)),
                            A = A1)

cr1_minrep_m <- tam.mml.2pl(cr1_minrep,
                            group = cr1_language_group,
                            irtmodel = "GPCM",
                            beta.fixed = cbind(c(1:3), 
                                               1, c(0, 0, 0)),
                            A = A1,
                            xsi.fixed = cbind(which(cr1_minrep_m$xsi.fixed.estimated[,2] == 0), 
                                              which(cr1_minrep_m$xsi.fixed.estimated[,2] != 0)))

cr1_minrep_m2 <- tam.mml.2pl(cr1_minrep,
                             group = cr1_language_group,
                             irtmodel = "GPCM",
                             beta.fixed = cbind( c(1:3), 
                                                 1, c(0, 0, 0)))

cr1_minrep_lr_ef <- IRT.compareModels(cr1_minrep_m,
                                   cr1_minrep_m2)


